import 'package:flutter/material.dart';
import 'dart:async';

class SimpleDialogDemo extends StatefulWidget {
  SimpleDialogDemo({Key key}) : super(key: key);

  @override
  _SimpleDialogDemoState createState() => _SimpleDialogDemoState();
}

class _SimpleDialogDemoState extends State<SimpleDialogDemo> {

  String _choise = "Nothing";

  Future _openSimpleDialog() async {
    final MyOption myOption = await showDialog(
      context: context,
      builder: (BuildContext context) {
        return SimpleDialog(
          title: Text("SimpleDialog Title"),
          children: [
            SimpleDialogOption(
              child: Text("Option A"),
              onPressed: () {
                Navigator.pop(context, MyOption.A);
              },
            ),
            SimpleDialogOption(
              child: Text("Option B"),
              onPressed: () {
                Navigator.pop(context, MyOption.B);
              },
            ),
            SimpleDialogOption(
              child: Text("Option C"),
              onPressed: () {
                Navigator.pop(context, MyOption.C);
              },
            ),
          ],
        );
      }
    );

    debugPrint("tap: $myOption");

    setState(() {
      _choise = myOption.toString();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("SimpleDialogDemo"),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text("You Choise: $_choise"),
              ],
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.format_list_numbered),
        onPressed: _openSimpleDialog,
      ),
    );
  }
}

enum MyOption {
  A, B, C
}